

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  <meta name="description" content="SVG学习介绍 SVG 指可伸缩矢量图形 (Scalable Vector Graphics)SVG 用来定义用于网络的基于矢量的图形SVG 使用 XML 格式定义图形SVG 图像在放大或改变尺寸的情况下其图形质量不会有所损失SVG 是万维网联盟的标准SVG 与诸如 DOM 和 XSL 之类的 W3C 标准是一个整体  学习svg的目的，是为了能在前端页面实现更多有意思的效果。以下就是本人的学习笔">
<meta property="og:type" content="article">
<meta property="og:title" content="SVG学习">
<meta property="og:url" content="http://yoursite.com/2022/09/19/SVG%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="Food-Billboard">
<meta property="og:description" content="SVG学习介绍 SVG 指可伸缩矢量图形 (Scalable Vector Graphics)SVG 用来定义用于网络的基于矢量的图形SVG 使用 XML 格式定义图形SVG 图像在放大或改变尺寸的情况下其图形质量不会有所损失SVG 是万维网联盟的标准SVG 与诸如 DOM 和 XSL 之类的 W3C 标准是一个整体  学习svg的目的，是为了能在前端页面实现更多有意思的效果。以下就是本人的学习笔">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-09-19T09:16:00.000Z">
<meta property="article:modified_time" content="2022-10-09T06:08:01.000Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="css svg">
<meta name="twitter:card" content="summary_large_image">
  
  <title>SVG学习 - Food-Billboard</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<!-- hexo injector head_end start -->
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/toubudaziji.css"></link>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/shubiao.css"></link>
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Fluid</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/project">
                <i class="iconfont icon-books"></i>
                项目
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/images/SVG%E5%AD%A6%E4%B9%A0/background.webp') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="SVG学习">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-09-19 17:16" pubdate>
        2022年9月19日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      7.2k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      22 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">SVG学习</h1>
            
            <div class="markdown-body">
              <h1 id="SVG学习"><a href="#SVG学习" class="headerlink" title="SVG学习"></a>SVG学习</h1><h2 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h2><blockquote>
<p>SVG 指可伸缩矢量图形 (Scalable Vector Graphics)<br>SVG 用来定义用于网络的基于矢量的图形<br>SVG 使用 XML 格式定义图形<br>SVG 图像在放大或改变尺寸的情况下其图形质量不会有所损失<br>SVG 是万维网联盟的标准<br>SVG 与诸如 DOM 和 XSL 之类的 W3C 标准是一个整体</p>
</blockquote>
<p>学习<code>svg</code>的目的，是为了能在前端页面实现更多有意思的效果。<br>以下就是本人的学习笔记。  </p>
<h2 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h2><h3 id="svg"><a href="#svg" class="headerlink" title="svg"></a>svg</h3><p><code>svg</code>标签的属性  </p>
<ul>
<li>width &amp; height  </li>
<li>version 版本  </li>
<li>xmlns 命名空间  </li>
<li>viewbox 可视区域<br>此属性表示裁剪一个矩形区域作为最终的可视区域（left top width height）<br>比如<code>20 20 100 100</code>表示能看到左上角(20, 20)为起点的宽高均为100的矩形区域。   </li>
</ul>
<h3 id="一些常用的属性"><a href="#一些常用的属性" class="headerlink" title="一些常用的属性"></a>一些常用的属性</h3><p>基本上这些属性都和<code>css</code>通用。  </p>
<h4 id="width-amp-height-amp-x-amp-y"><a href="#width-amp-height-amp-x-amp-y" class="headerlink" title="width &amp; height &amp; x &amp; y"></a>width &amp; height &amp; x &amp; y</h4><p>元素的宽高位置。  </p>
<h4 id="fill"><a href="#fill" class="headerlink" title="fill"></a>fill</h4><p>颜色填充  </p>
<svg width="100" height="100">
  <rect fill="red" width="50" height="50"></rect>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;rect fill=&quot;red&quot; width=&quot;50&quot; height=&quot;50&quot;&gt;&lt;/rect&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="stroke"><a href="#stroke" class="headerlink" title="stroke"></a>stroke</h4><p>描边  </p>
<svg width="100" height="100">
  <rect x="10" y="10" fill="none" stroke="#f00" width="50" height="50"></rect>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;rect x=&quot;10&quot; y=&quot;10&quot; fill=&quot;none&quot; stroke=&quot;#f00&quot; width=&quot;50&quot; height=&quot;50&quot;&gt;&lt;/rect&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="stroke-width"><a href="#stroke-width" class="headerlink" title="stroke-width"></a>stroke-width</h4><p>描边的线条尺寸  </p>
<svg width="100" height="100">
  <rect x="10" y="10" fill="none" stroke="#f00" stroke-width="10" width="50" height="50"></rect>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;rect x=&quot;10&quot; y=&quot;10&quot; fill=&quot;none&quot; stroke=&quot;#f00&quot; stroke-width=&quot;10&quot; width=&quot;50&quot; height=&quot;50&quot;&gt;&lt;/rect&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="stroke-dashoffset"><a href="#stroke-dashoffset" class="headerlink" title="stroke-dashoffset"></a>stroke-dashoffset</h4><p>设置虚线的偏移量</p>
<svg width="200" height="100">
  <polyline points="20 20 150 20" stroke-dasharray="50 10" stroke="red" stroke-width="5"></polyline>
  <polyline points="20 50 150 50" stroke-dasharray="50 10" stroke="blue" stroke-width="5" stroke-dashoffset="20"></polyline>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;200&quot; height=&quot;100&quot;&gt;<br>  &lt;polyline points=&quot;20 20 150 20&quot; stroke-dasharray=&quot;50 10&quot; stroke=&quot;red&quot; stroke-width=&quot;5&quot;&gt;&lt;/polyline&gt;<br>  &lt;polyline points=&quot;20 50 150 50&quot; stroke-dasharray=&quot;50 10&quot; stroke=&quot;blue&quot; stroke-width=&quot;5&quot; stroke-dashoffset=&quot;20&quot;&gt;&lt;/polyline&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="stroke-linejoin"><a href="#stroke-linejoin" class="headerlink" title="stroke-linejoin"></a>stroke-linejoin</h4><p>转折点的样式</p>
<svg width="200" height="200">
  <polyline stroke-linejoin="miter" points="0 0 0 50 50 50" stroke="red" stroke-width="20" fill="none"></polyline>
  <polyline stroke-linejoin="round" points="50 50 50 100 100 100" stroke="blue" stroke-width="20" fill="none"></polyline>
  <polyline stroke-linejoin="bevel" points="100 100 100 150 150 150" stroke="blue" stroke-width="20" fill="none"></polyline>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;200&quot; height=&quot;100&quot;&gt;<br>  &lt;polyline stroke-linejoin=&quot;miter&quot; points=&quot;20 20 40 50 60 70&quot; stroke=&quot;red&quot; stroke-width=&quot;5&quot;&gt;&lt;/polyline&gt;<br>  &lt;polyline stroke-linejoin=&quot;round&quot; points=&quot;20 20 40 50 60 70&quot; stroke=&quot;blue&quot; stroke-width=&quot;5&quot;&gt;&lt;/polyline&gt;<br>  &lt;polyline stroke-linejoin=&quot;bevel&quot; points=&quot;20 20 40 50 60 70&quot; stroke=&quot;blue&quot; stroke-width=&quot;5&quot;&gt;&lt;/polyline&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>
<h4 id="stroke-opacity"><a href="#stroke-opacity" class="headerlink" title="stroke-opacity"></a>stroke-opacity</h4><p>描边线条的透明度  </p>
<h4 id="stroke-linecap"><a href="#stroke-linecap" class="headerlink" title="stroke-linecap"></a>stroke-linecap</h4><p>描边的末端形状</p>
<svg width="100" height="100">
  <g fill="none" stroke="black" stroke-width="6">
    <path stroke-linecap="butt" d="M5 20 l65 0" />
    <path stroke-linecap="round" d="M5 40 l65 0" />
    <path stroke-linecap="square" d="M5 60 l65 0" />
  </g>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;g fill=&quot;none&quot; stroke=&quot;black&quot; stroke-width=&quot;6&quot;&gt;<br>    &lt;path stroke-linecap=&quot;butt&quot; d=&quot;M5 20 l65 0&quot; /&gt;<br>    &lt;path stroke-linecap=&quot;round&quot; d=&quot;M5 40 l65 0&quot; /&gt;<br>    &lt;path stroke-linecap=&quot;square&quot; d=&quot;M5 60 l65 0&quot; /&gt;<br>  &lt;/g&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="stroke-dasharray"><a href="#stroke-dasharray" class="headerlink" title="stroke-dasharray"></a>stroke-dasharray</h4><p>绘制虚线  </p>
<p>格式为<code>length margin, length margin, ...</code>  </p>
<ul>
<li>length 虚线长度  </li>
<li>margin 虚线间距  </li>
</ul>
<svg width="100" height="100">
  <g fill="none" stroke="black" stroke-width="4">
    <path stroke-dasharray="5,5" d="M5 20 l215 0" />
    <path stroke-dasharray="10,10" d="M5 40 l215 0" />
    <path stroke-dasharray="20,10,5,5,5,10" d="M5 60 l215 0" />
  </g>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;g fill=&quot;none&quot; stroke=&quot;black&quot; stroke-width=&quot;4&quot;&gt;<br>    &lt;path stroke-dasharray=&quot;5,5&quot; d=&quot;M5 20 l215 0&quot; /&gt;<br>    &lt;path stroke-dasharray=&quot;10,10&quot; d=&quot;M5 40 l215 0&quot; /&gt;<br>    &lt;path stroke-dasharray=&quot;20,10,5,5,5,10&quot; d=&quot;M5 60 l215 0&quot; /&gt;<br>  &lt;/g&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="rx-amp-ry"><a href="#rx-amp-ry" class="headerlink" title="rx &amp; ry"></a>rx &amp; ry</h4><p><strong>矩形</strong>的圆角<br><strong>椭圆</strong>的水平和垂直尺寸  </p>
<h4 id="cx-amp-cy"><a href="#cx-amp-cy" class="headerlink" title="cx &amp; cy"></a>cx &amp; cy</h4><p><strong>圆形</strong>的圆心  </p>
<h4 id="r"><a href="#r" class="headerlink" title="r"></a>r</h4><p><strong>圆形</strong>的半径   </p>
<h3 id="shapes-形状和文字"><a href="#shapes-形状和文字" class="headerlink" title="shapes 形状和文字"></a>shapes 形状和文字</h3><h4 id="rect（矩形）"><a href="#rect（矩形）" class="headerlink" title="rect（矩形）"></a>rect（矩形）</h4><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
  <rect width="50" height="50" fill="red" stroke-width="1" stroke="rgb(0,0,0)"/>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot; &gt;<br>  &lt;rect width=&quot;50&quot; height=&quot;50&quot; fill=&quot;red&quot; stroke-width=&quot;1&quot; stroke=&quot;rgb(0,0,0)&quot;/&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="circle（圆形）"><a href="#circle（圆形）" class="headerlink" title="circle（圆形）"></a>circle（圆形）</h4><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
  <circle cx="30" cy="30" r="10" fill="red" stroke-width="1" stroke="rgb(0,0,0)"/>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;circle cx=&quot;30&quot; cy=&quot;30&quot; r=&quot;10&quot; fill=&quot;red&quot; stroke-width=&quot;1&quot; stroke=&quot;rgb(0,0,0)&quot;/&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="ellipse（椭圆）"><a href="#ellipse（椭圆）" class="headerlink" title="ellipse（椭圆）"></a>ellipse（椭圆）</h4><p>类似于<strong>圆形</strong>，只是把<code>r</code>变成了<code>rx</code>和<code>ry</code>。  </p>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
  <ellipse cx="30" cy="30" rx="10" ry="5" fill="red" stroke-width="1" stroke="rgb(0,0,0)"/>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;ellipse cx=&quot;30&quot; cy=&quot;30&quot; rx=&quot;10&quot; ry=&quot;5&quot; fill=&quot;red&quot; stroke-width=&quot;1&quot; stroke=&quot;rgb(0,0,0)&quot;/&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="line（直线）"><a href="#line（直线）" class="headerlink" title="line（直线）"></a>line（直线）</h4><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
  <line x1='0' y1='0' x2='100' y2='100' stroke-width="1" stroke="rgb(0,0,0)"/>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;line x1=&#x27;0&#x27; y1=&#x27;0&#x27; x2=&#x27;100&#x27; y2=&#x27;100&#x27; stroke-width=&quot;1&quot; stroke=&quot;rgb(0,0,0)&quot;/&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="polyline（多线段）"><a href="#polyline（多线段）" class="headerlink" title="polyline（多线段）"></a>polyline（多线段）</h4><p><code>points</code>为点的集合，格式为<code>x1 y1, x2 y2, ...</code>  </p>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
  <polyline points="0 0, 100 0, 0 100, 0 0" stroke-width="1" stroke="rgb(0,0,0)" fill="none" />
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;polyline points=&quot;0 0, 100 0, 0 100, 0 0&quot; stroke-width=&quot;1&quot; stroke=&quot;rgb(0,0,0)&quot; fill=&quot;none&quot; /&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>
<h4 id="polygon（多边形）"><a href="#polygon（多边形）" class="headerlink" title="polygon（多边形）"></a>polygon（多边形）</h4><p>和<code>polyline</code>相同，使用<code>points</code>设置点  </p>
<svg height="210" width="500">
  <polygon points="100 10, 40 198, 190 78, 10 78, 160 198" fill="lime" stroke="purple" stroke-width="5" fill-rule="nonzero" />
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot; width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;polygon points=&quot;100 10, 40 198, 190 78, 10 78, 160 198&quot; fill=&quot;lime&quot; stroke=&quot;purple&quot; stroke-width=&quot;5&quot; fill-rule=&quot;nonzero&quot; /&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h4 id="path（路径）"><a href="#path（路径）" class="headerlink" title="path（路径）"></a>path（路径）</h4><p>重点来了，这个应该是平常用到的最多的一个东西。  </p>
<p>关键的属性在<code>d</code>上，描述了元素的整体路径的形状。<br>以下是相关的语法。  </p>
<blockquote>
<p>M = moveto 移动到某个位置<br>L = lineto 从当前点连线到指定点<br>H = horizontal lineto 从当前点水平连接指定点<br>V = vertical lineto 从当前点垂直连接指定点<br>C = curveto 三次贝塞尔曲线<br>S = smooth curveto 三次平滑贝塞尔曲线<br>Q = quadratic Bézier curve 二次贝塞尔曲线<br>T = smooth quadratic Bézier curveto 平滑二次贝塞尔曲线<br>A = elliptical Arc 圆弧（x轴半径，y轴半径，旋转角度，是否选择弧长较长的一段0短边|1长边，顺时针绘制1|逆时针0，终点x轴坐标，终点y轴坐标）<br>Z = closepath  闭合路径  </p>
</blockquote>
<p>以上的字母，大小表示绝对位置，小写表示相对位置。  </p>
<p><code>d</code>以<code>M</code>开头，  </p>
<svg width="200" height="200">
  <path d="M10 10 L120 50 H140 V100" fill="none" stroke="red" stroke-width="2"></path>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;200&quot; height=&quot;200&quot;&gt;<br>  &lt;path d=&quot;M10 10 L120 50 H140 V100&quot; fill=&quot;none&quot; stroke=&quot;red&quot; stroke-width=&quot;2&quot;&gt;&lt;/path&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h5 id="A"><a href="#A" class="headerlink" title="A"></a>A</h5><p>从点(10, 10)开始，绘制x轴半径为50，y轴半径是20，旋转100度，以小弧度，逆时针到点（100， 100）处。  </p>
<svg width="200" height="200">
  <path d="M10 10 A50 20 100 0 0 100 100" fill="none" stroke="red" stroke-width="2"></path>
</svg>

<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs arduino">&lt;svg width=<span class="hljs-string">&quot;200&quot;</span> height=<span class="hljs-string">&quot;200&quot;</span>&gt;<br>  &lt;path d=<span class="hljs-string">&quot;M10 10 A50 20 180 1 0 100 100&quot;</span> fill=<span class="hljs-string">&quot;none&quot;</span> stroke=<span class="hljs-string">&quot;red&quot;</span> stroke-width=<span class="hljs-string">&quot;2&quot;</span>&gt;&lt;/path&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>


<h4 id="text（文本）"><a href="#text（文本）" class="headerlink" title="text（文本）"></a>text（文本）</h4><svg height="210" width="500">
  <text x="50" y="50" fill="lime">I am Daniel</text>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg height=&quot;210&quot; width=&quot;500&quot;&gt;<br>  &lt;text x=&quot;50&quot; y=&quot;50&quot; fill=&quot;lime&quot;&gt;I am Daniel&lt;/text&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><h4 id="defs"><a href="#defs" class="headerlink" title="defs"></a>defs</h4><p>将一些特殊的配置放在<code>defs</code>标签中，比如<strong>滤镜</strong>、<strong>渐变</strong>、<strong>阴影</strong>等。  </p>
<svg width="100" height="100">
  <defs>
    <filter id="f1">
      <feGaussianBlur in="SourceGraphic" stdDeviation="15" />
    </filter>
  </defs>
  <rect width="90" height="90" stroke="green" stroke-width="3" fill="yellow" filter="url(#f1)" />
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;defs&gt;<br>    &lt;filter id=&quot;f1&quot;&gt;<br>      &lt;feGaussianBlur in=&quot;SourceGraphic&quot; stdDeviation=&quot;15&quot; /&gt;<br>    &lt;/filter&gt;<br>  &lt;/defs&gt;<br>  &lt;rect width=&quot;90&quot; height=&quot;90&quot; stroke=&quot;green&quot; stroke-width=&quot;3&quot; fill=&quot;yellow&quot; filter=&quot;url(#f1)&quot; /&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<h5 id="filter（滤镜）"><a href="#filter（滤镜）" class="headerlink" title="filter（滤镜）"></a>filter（滤镜）</h5><p>有如下滤镜：</p>
<blockquote>
<p>feBlend - 与图像相结合的滤镜<br>feColorMatrix - 用于彩色滤光片转换<br>feComponentTransfer<br>feComposite<br>feConvolveMatrix<br>feDiffuseLighting<br>feDisplacementMap<br>feFlood<br>feGaussianBlur<br>feImage<br>feMerge<br>feMorphology<br>feOffset - 过滤阴影<br>feSpecularLighting<br>feTile<br>feTurbulence<br>feDistantLight - 用于照明过滤<br>fePointLight - 用于照明过滤<br>feSpotLight - 用于照明过滤</p>
</blockquote>
<p>等等。  </p>
<h5 id="渐变"><a href="#渐变" class="headerlink" title="渐变"></a>渐变</h5><ul>
<li>线性渐变  </li>
</ul>
<svg width="100" height="100">
  <defs>
    <linearGradient id="linear" x1="0%" y1="0%" x2="100%" y2="100%">
      <stop offset="0%" stop-color="red" stop-opacity="1"></stop>
      <stop offset="100%" stop-color="yellow" stop-opacity="1"></stop>
    </linearGradient>
  </defs>
  <rect width="50" height="50" fill="url(#linear)"></rect>
</svg>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs svg">&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;defs&gt;<br>    &lt;linearGradient id=&quot;linear&quot; x1=&quot;0%&quot; y1=&quot;0%&quot; x2=&quot;100%&quot; y2=&quot;100%&quot;&gt;<br>      &lt;stop offset=&quot;0%&quot; stop-color=&quot;red&quot; stop-opacity=&quot;1&quot;&gt;&lt;/stop&gt;<br>      &lt;stop offset=&quot;100%&quot; stop-color=&quot;yellow&quot; stop-opacity=&quot;1&quot;&gt;&lt;/stop&gt;<br>    &lt;/linearGradient&gt;<br>  &lt;/defs&gt;<br>  &lt;rect width=&quot;50&quot; height=&quot;50&quot; fill=&quot;url(#linear)&quot;&gt;&lt;/rect&gt;<br>&lt;/svg&gt;<br></code></pre></td></tr></table></figure>

<ul>
<li>x1、y1、x2、y2表示线性渐变的方向  </li>
<li>id 表示渐变的名称  </li>
<li>stop 表示内部颜色的变化步骤  <ul>
<li>offset 表示线性的位置  </li>
<li>stop-color 表示颜色  </li>
<li>stop-opacity 表示透明度  </li>
</ul>
</li>
</ul>
<ul>
<li>径向渐变</li>
</ul>
<svg width="100" height="100">
  <defs>
    <radialGradient id="radial" r="100%" cx="100%" cy="50%" fx="50%" fy="50%">
      <stop offset="0%" stop-color="red" stop-opacity="1"></stop>
      <stop offset="100%" stop-color="yellow" stop-opacity="1"></stop>
    </radialGradient>
  </defs>
  <circle r="50" cx="50" cy="50" fill="url(#radial)"></rect>
</svg>

<p>  与线性渐变类似  </p>
<ul>
<li>r 表示渐变的圆形大小  </li>
<li>fx、fy 表示渐变的焦点，也可以说是一个灯光效果，或者说渐变<code>圆心</code>在图形上的位置。    </li>
<li>fr 表示焦点的大小  </li>
<li>cx、cy 表示渐变结束的圆心位置  </li>
</ul>
<h2 id="结束"><a href="#结束" class="headerlink" title="结束"></a>结束</h2><p>以上就是本人相关的笔记。<br>下面给到一些链接：<br><a target="_blank" rel="noopener" href="https://c.runoob.com/more/svgeditor/">编辑器</a><br><a target="_blank" rel="noopener" href="https://www.runoob.com/svg/svg-reference.html">API参考</a>  </p>
<h2 id="附增"><a href="#附增" class="headerlink" title="附增"></a>附增</h2><p>这里保存一些平常看到的有意思的<code>svg</code>效果👍。    </p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/svg/">svg</a>
                    
                      <a class="hover-with-bg" href="/categories/svg/css/">css</a>
                    
                      <a class="hover-with-bg" href="/categories/svg/css/%E5%89%8D%E7%AB%AF/">前端</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/css-svg/">css svg</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/10/11/%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81%E7%BB%99Github%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">贡献代码给Github开源项目</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/09/12/%E4%B8%80%E5%88%9B%E8%81%9A%E5%AE%BD%E5%AD%A6%E4%B9%A0/">
                        <span class="hidden-mobile">一创聚宽学习</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数...</span> <span id="times">载入时分秒...</span> <script src="/js/duration.js"></script> <script src="/js/code-viewer.js"></script> </div> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


<!-- hexo injector body_end start -->
  <script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiantiao.js"></script>
  <script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxingxing.js"></script>
  <script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/dianjichuzi.js"></script>
<!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"right","width":150,"height":300,"mobile":{"show":true}},"log":false});</script></body>
</html>
